﻿<?php require_once('../wp-blog-header.php'); ?>
<?php get_header(); ?>
<SCRIPT type=text/javascript src="javascripts.js"></SCRIPT>
<?php
	// require_once('checkSession.php');
	require_once('conn.php');	

	$no = $_GET['no'];	
	$searchMobileNO = $_POST['searchMobileNO'];
	if ($no !='')
	{
		$searchMobileNO = $no;
	}
	
	if ($searchMobileNO=="*")
	{
		$exec="select * from buyRecord order by buyDate DESC";
	}
	else
	{		
		$exec="select * from buyRecord where mobileNO='".$searchMobileNO."' order by name DESC, buyDate DESC";
	}	
	$result=mysql_query($exec);
	if (mysql_num_rows($result) < 1)
	{
		echo '<script language="JavaScript">window.alert("您查询的会员信息不存在，请核对会员手机号码");</script>'; 
		echo '<script language="JavaScript">window.location.href="inputForm.php";</script>'; 
	}
	
	// socre2gift
	if ($searchMobileNO!="*")
	{
		$exec_customer = "select * from customer where mobileNO='".$searchMobileNO."'";
		$result_customer = mysql_query($exec_customer);
		$row_customer = mysql_fetch_row($result_customer);
		$id_customer = $row_customer[0];
		$name_customer = $row_customer[3];
		$query = "SELECT * FROM pairMap WHERE mapIndex='".$row_customer[4]."'";
		$queryresult = mysql_query($query);
		$trans = mysql_fetch_object($queryresult);			
		$sex_customer = $trans->mapName;
		
		$exec_score_total = "select sum(score) from buyRecord where mobileNO='".$searchMobileNO."'";
		$result_score_total = mysql_query($exec_score_total);
		$row_score_total=mysql_fetch_row($result_score_total);	
		$score_total = $row_score_total[0];
		
		// var_dump($score_total);
		$exec_score_used = "select sum(score) from giftRecord where mobileNO='".$searchMobileNO."'";
		//var_dump($exec_score_used);
		$result_score_used = mysql_query($exec_score_used);
		$row_score_used = mysql_fetch_row($result_score_used);
		//var_dump($row_score_used);
		$score_used = $row_score_used[0];
		//var_dump($score_used);
		
		$score_available = $score_total - $score_used;
		
		echo '<form method="POST" action="score2gift.php" name="send">';
		echo '<table>';
			echo '<tr>';
				echo '<td>'; echo "<input type='text' value='".$id_customer."' name='id_customer'>"; echo '</td>';
				echo '<td>'; echo '<br>'; echo '</td>';
				echo '<td>'; echo '<br>'; echo '</td>';
			echo '</tr>';	
			echo '<tr>';
				echo '<td>'; echo "<input type='text' value='".$name_customer."' name='name_customer'>"; echo '</td>';
				echo '<td>'; echo "<input type='text' value='".$sex_customer."' name='sex_customer'>"; echo '</td>';
				echo '<td>'; echo '<br>'; echo '</td>';
			echo '</tr>';
			echo '<tr>';
				echo '<td>'; echo '会员帐号:'; echo '</td>';
				echo '<td>'; echo "<input type='text' value='".$searchMobileNO."' name='searchMobileNO'>"; echo '</td>';
				echo '<td>'; echo '<br>'; echo '</td>';
			echo '</tr>';		
			echo '<tr>';
				echo '<td>'; echo '可用积分:'; echo '</td>';
				echo '<td>'; echo "<input type='text' value='".$score_available."' name='score_available'>"; echo '</td>';
				echo '<td>'; echo '<br>'; echo '</td>';
			echo '</tr>';	
		echo '</table>';
		
		echo '<br>';
		
		$exec_gift="select * from giftRecord where mobileNO='".$searchMobileNO."' order by changeDate DESC";
		$result_gift=mysql_query($exec_gift);
		
		echo '<table>';
			echo '<tr>';
				echo '<td>'; echo '积分兑换记录:'; echo '</td>';
				echo '<td>'; echo '<br>'; echo '</td>';
			echo '</tr>';
			// 积分兑换记录，逐个打出，两列，时间和兑换记录
			while ($row_gift=mysql_fetch_row($result_gift))
			{
				echo '<tr>';
					$changeDate = $row_gift[5];
					echo '<td>'; echo $changeDate; echo '</td>';
					$score = $row_gift[3];
					$gift = $row_gift[4];
					$record = $score."积分兑换".$gift;
					echo '<td>'; echo $record; echo '</td>';
				echo '</tr>';			
			}			
		echo '</table>';	
		
		echo '<br>';
		echo '<br>';
		
		echo '<table>';
			echo '<tr>';
				echo '<td>'; echo '使用积分'; echo '</td>';
				echo '<td>'; echo '兑换礼品'; echo '</td>';
				echo '<td>'; echo '兑换地点'; echo '</td>';
				echo '<td>'; echo '经办人'; echo '</td>';
				echo '<td>'; echo '&nbsp;&nbsp;&nbsp;&nbsp;'; echo '</td>';
			echo '</tr>';
			echo '<tr>';
				echo '<td>'; echo '<input type="text" name="score_lose"'; echo '</td>';
				echo '<td>'; echo '<input type="text" name="gift_get">'; echo '</td>';
				echo '<td>';
					echo '<select name="shopID" >';
					echo '<option value="shop001">深圳丰盛町店';
					echo '<option value="shop000">淘宝顶电蔡司';
					echo '</select>';
				echo '</td>	';
				echo '<td>'; 
					echo '<select name="optID" >';
					echo '<option value="opt001">陈伟宣';
					echo '<option value="opt000">李涛';
					echo '<option value="opt002">李敏';
					echo '</select>';							
				echo '</td>';
				echo '<td>'; echo '<br>'; echo '</td>';			
				echo '<td><input type="submit" value="确认兑换"></td>';
			echo '</tr>';
		echo '</table>';
		echo '</form>';
	}
	
	echo '<br>';
	echo '<br>';	
	//var_dump($searchMobileNO);
	//var_dump($result);
	
	echo '<form>';
		while ($row=mysql_fetch_row($result))
		{
			$id_buyRecord=$row[0];
			$mobileNO=$row[1];
			$name=$row[2];
			
			$query = "SELECT * FROM pairMap WHERE mapIndex='".$row[3]."'";
			$queryresult = mysql_query($query);
			$trans = mysql_fetch_object($queryresult);			
			$sex = $trans->mapName;

			$score=$row[4]; 
			$rDomin=$row[5]; 
			$rNaked=$row[6]; 
			$rSph=$row[7]; 
			$rCyl=$row[8]; 
			$rAxis=$row[9]; 
			$rCorrect=$row[10];
			$rAdd=$row[11]; 
			$rFH=$row[12]; 
			$rPD=$row[13]; 
			$lDomin=$row[14]; 
			$lNaked=$row[15]; 			
			$lSph=$row[16]; 
			$lCyl=$row[17]; 
			$lAxis=$row[18]; 
			$lCorrect=$row[19];
			$lAdd=$row[20]; 
			$lFH=$row[21]; 
			$lPD=$row[22]; 
			$buyDate=$row[23]; 
			$comments=$row[26];
			
			$query = "SELECT * FROM pairMap WHERE mapIndex='".$row[24]."'";
			$queryresult = mysql_query($query);
			$trans = mysql_fetch_object($queryresult);		
			$shopID = $trans->mapName;
			
			$query = "SELECT * FROM pairMap WHERE mapIndex='".$row[25]."'";
			$queryresult = mysql_query($query);
			$trans = mysql_fetch_object($queryresult);		
			$optID = $trans->mapName;		
			
			echo '<hr>';
			echo '<table align="center">';
				echo '<tr align="center">';
					echo '<td>'; echo $buyDate; echo '</td>';
					echo '<td>'; echo ''; echo '</td>';
					echo '<td>'; echo $name; echo '</td>';
					echo '<td>'; echo $sex; echo '</td>';
					echo '<td>'; echo ''; echo '</td>';
					echo '<td>'; echo '本次积分:'; echo '</td>';
					echo '<td>'; echo $score; echo '</td>';
					echo '<td><input type="button" value="填写回访记录" onclick="OpenInputRevisitRecordForm('.$id_buyRecord.','.$mobileNO.')"></td>';
				echo '</tr>';	
				echo '<tr><td><br></td></tr>';
				echo '<tr>';
					echo '<td>'; echo '视力方案:'; echo '</td>';
					echo '<td colspan=9>'; echo $comments; echo '</td>';
				echo '</tr>';
				// 显示该条购买记录的多条回访记录，按照时间先后顺序排列
				// var_dump($id_buyRecord);
				$exec_revisitRecord="select * from revisitRecord where id_buyRecord='".$id_buyRecord."'";
				$result_revisitRecord=mysql_query($exec_revisitRecord);
				//var_dump($id_buyRecord);
				//var_dump(mysql_num_rows($result_revisitRecord));
				if (mysql_num_rows($result_revisitRecord) >= 1)
				{				
					echo '<tr>';
						echo '<td>'; echo '回访日期'; echo '</td>';
						echo '<td>'; echo '总体评分'; echo '</td>';
						echo '<td colspan=7>'; echo '顾客反馈详情'; echo '</td>';
						echo '<td>'; echo '回访人'; echo '</td>';
					echo '</tr>';	
					while ($row_revisit=mysql_fetch_row($result_revisitRecord))
					{
						// var_dump($row_revisit);
						$revisitDate=$row_revisit[4];
						$revisitScore=$row_revisit[3];
						$feedback=$row_revisit[5];
						$revisitor=$row_revisit[6];
						$revisit_query = "SELECT * FROM pairMap WHERE mapIndex='".$revisitor."'";
						$revisit_queryresult = mysql_query($revisit_query);
						$revisit_trans = mysql_fetch_object($revisit_queryresult);		
						$revisitor = $revisit_trans->mapName;						
						echo '<tr>';
							echo '<td>'; echo $revisitDate; echo '</td>';
							echo '<td>'; echo '<input type="text" size="8" disabled="disabled" value='.$revisitScore.'>'; echo '</td>';
							echo '<td colspan=7>'; echo $feedback; echo '</td>';
							echo '<td>'; echo '<input type="text" size="8" disabled="disabled" value='.$revisitor.'>'; echo '</td>';
						echo '</tr>';
					}
				}				
				echo '<tr><td><br></td></tr>';
				echo '<tr align="center">';
					echo '<td>'; echo ''; echo '</td>';
					echo '<td>'; echo '利眼'; echo '</td>';
					echo '<td>'; echo '裸眼视力'; echo '</td>';
					echo '<td>'; echo '近视/远视'; echo '</td>';
					echo '<td>'; echo '散光'; echo '</td>';
					echo '<td>'; echo '散光轴位'; echo '</td>';
					echo '<td>'; echo '矫正视力'; echo '</td>';
					echo '<td>'; echo '下加光'; echo '</td>';
					echo '<td>'; echo '瞳高'; echo '</td>';
					echo '<td>'; echo '瞳距'; echo '</td>';
				echo '</tr>';
				echo '<tr align="center">';
					echo '<td>'; echo '右眼:'; echo '</td>';					
					echo '<td>'; echo '<input type="text" size="8" disabled="disabled" value='.$rDomin.'>'; echo '</td>';
					echo '<td>'; echo '<input type="text" size="8" disabled="disabled" value='.$rNaked.'>'; echo '</td>';
					echo '<td>'; echo '<input type="text" size="8" disabled="disabled" value='.$rSph.'>'; echo '</td>';
					echo '<td>'; echo '<input type="text" size="8" disabled="disabled" value='.$rCyl.'>'; echo '</td>';
					echo '<td>'; echo '<input type="text" size="8" disabled="disabled" value='.$rAxis.'>'; echo '</td>';
					echo '<td>'; echo '<input type="text" size="8" disabled="disabled" value='.$rCorrect.'>'; echo '</td>';
					echo '<td>'; echo '<input type="text" size="8" disabled="disabled" value='.$rAdd.'>'; echo '</td>';
					echo '<td>'; echo '<input type="text" size="8" disabled="disabled" value='.$rFH.'>'; echo '</td>';
					echo '<td>'; echo '<input type="text" size="8" disabled="disabled" value='.$rPD.'>'; echo '</td>';
				echo '</tr>';	
				echo '<tr align="center">';
					echo '<td>'; echo '左眼:'; echo '</td>';
					echo '<td>'; echo '<input type="text" size="8" disabled="disabled" value='.$lDomin.'>'; echo '</td>';
					echo '<td>'; echo '<input type="text" size="8" disabled="disabled" value='.$lNaked.'>'; echo '</td>';
					echo '<td>'; echo '<input type="text" size="8" disabled="disabled" value='.$lSph.'>'; echo '</td>';
					echo '<td>'; echo '<input type="text" size="8" disabled="disabled" value='.$lCyl.'>'; echo '</td>';
					echo '<td>'; echo '<input type="text" size="8" disabled="disabled" value='.$lAxis.'>'; echo '</td>';
					echo '<td>'; echo '<input type="text" size="8" disabled="disabled" value='.$lCorrect.'>'; echo '</td>';
					echo '<td>'; echo '<input type="text" size="8" disabled="disabled" value='.$lAdd.'>'; echo '</td>';
					echo '<td>'; echo '<input type="text" size="8" disabled="disabled" value='.$lFH.'>'; echo '</td>';
					echo '<td>'; echo '<input type="text" size="8" disabled="disabled" value='.$lPD.'>'; echo '</td>';
				echo '</tr>';		
				echo '<tr><td><br></td></tr>';
				echo '<tr align="center">';
					echo '<td>'; echo ''; echo '</td>';
					echo '<td>'; echo ''; echo '</td>';
					echo '<td>'; echo ''; echo '</td>';
					echo '<td>'; echo ''; echo '</td>';
					echo '<td>'; echo ''; echo '</td>';
					echo '<td>'; echo ''; echo '</td>';
					echo '<td>'; echo '分店:'; echo '</td>';
					echo '<td>'; echo $shopID; echo '</td>';
					echo '<td>'; echo '视光师:'; echo '</td>';
					echo '<td>'; echo $optID; echo '</td>';
				echo '</tr>';		
			echo '</table>';
			echo '<hr>';
		}
	echo '</form>';
?>
<?php get_footer(); ?>